#ifndef ANIMATIONCONTROLLER_H
#define ANIMATIONCONTROLLER_H

#include <QList>
#include <QListView>
#include <QTreeView>
#include <QColumnView>
#include <QStringListModel>
#include <QGraphicsView>
#include <QPixmap>
#include <QGraphicsPixmapItem>
#include <QTimer>

#include "actionmodel.h"
#include "framemodel.h"
#include "animationdatahandler.h"
#include "CommonMarcro.h"
#include "sourceframemodel.h"
#include "graphicsframemodel.h"

//plist
#include "plistparser.h"
#include <QDebug>
#include "utilitfile.h"

//action
#include "action.h"


class MainController : public QObject
{
    Q_OBJECT

public:
    explicit MainController(QObject* parent = 0);
    ~MainController();

    void initModel();
    void setupConnect();

    void setSourceFrameListView(QListView* listView);

    void setActionListView(QTreeView* listView);
    void setFrameListView(QTreeView* listView);
    void setFrameGraphicsView(QGraphicsView* graphicsView);

    void createNewAction();
    void deleteAction();

    void addFrameToAction();
    void removeFrame();

    inline bool hasAddPlist(const QString& fileName){return m_plistfileNameList.indexOf(fileName) != -1;}

    bool parsePlistFile(const QString& fileName);    
    void recordPlistInfo(const QString& fileName);

    bool saveDataToFile(const QString& fileName);
    bool loadDataFromFile(const QString& fileName);

    void playCurrentAnimation();
    void stopAnimation();


 private:
    void setWorkDir(const QString& fileName);
    void stopTimer();
 signals:
    void notifyAppendNewAction();
    void notifDelelteActionData(QModelIndex& index);

 public slots:

 private slots:
    void playNextFrame();
 private:
    //plistParser
    PlistParser* m_plistParse;
    QListView* m_sourceframeListView;
    SourceFrameModel* m_sourceFrameModel;
    QItemSelectionModel* m_sourceSelectionModel;
    QStringList m_plistfileNameList;

    //action
    ActionModel* m_actionModel;
    QTreeView* m_actionListView;
    QItemSelectionModel* m_actionSelectModel;

    //frame
    FrameModel* m_frameModel;
    QTreeView* m_frameListView;
    QItemSelectionModel* m_frameSelectionModel;

    GraphicsFrameModel* m_framegraphicsModel;
    QGraphicsView* m_frameGraphicsView;

    QString m_workingDir;
    QTimer* m_timer;
    int m_curFrame;
    int m_maxFrame;

 private:
    static const int ANIMATION_DESPLAY_DELAY;

};

#endif // ANIMATIONCONTROLLER_H
